<?php
declare (strict_types = 1);

namespace app\api\controller;

use think\facade\Db;

use app\common\model\UploadFile as UploadFileModel;

/**
 * @title 图片上传
 * @description 接口说明
 */
class Upload extends Base
{
    function __construct(){
        parent::__construct();
        $param = input('param.');
        $token = isset($param['token'])?$param['token']:'';
        if($token) {
            $res = checkToken($param['token']);
            if ($res['code']==2) {
                return dyajaxReturn(-1, $res['msg']);
            }
            $this->user = json_decode($res['data'], true);
        }
    }
    /*
     * 图片上传
     * @param $filenames  文件域
     * @param $position  存放目录
    */
    public function image(){
        $res = msuploadimg('pic','images');
        if(!$res['code']){
            return dyajaxReturn($res['code'], $res['msg']);
        }
        //存入文件库
        $UploadFileModel = new UploadFileModel();
        $data['act'] = 'add';
        $data['storage'] = 'local';
        $data['file_name'] = $res['data']['imgurl'];
        $data['file_size'] = $res['data']['size'];
        $data['extension'] = $res['data']['ext'];
        $data['file_type'] = 'image';
        $data['is_user'] = $this->user['user_id'];
        $UploadFileModel->handle($data);

        return dyajaxReturn($res['code'], $res['msg'],$res['data']['imgurl']);
    }

    /*
     * 文件上传
     * @param $filenames  文件域
     * @param $position  存放目录
    */
    public function dyuploadfile(){
        return dyuploadfile('file',input('imgpath/s'));
    }


    //视频上传
    public function dyuploadVideo()
    {
        return dyuploadVideo('dyvideo',input('imgpath/s'));
    }

}
